<?php
/**
 * ============================================================================
 * 版权所有 多多科技，保留所有权利。
 * 网站地址: http://soft.duoduo123.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/

if(!defined('INDEX')){
	exit('Access Denied');
}

function act_wap_quan(){
	global $duoduo,$dd_tpl_data;
	$webset = $duoduo->webset;
	$dduser = $duoduo->dduser;
	
	include(DDROOT.'/comm/goods.class.php');
	$goods_class=new goods($duoduo);
	
	$page=$_GET['page']?$_GET['page']:1;
	$code='quan';
	$cid=(int)$_GET['cid'];
	$pagesize=10;
	$fromnum=($page-1)*$pagesize;
	
	$bankuai=dd_get_cache('bankuai');
	$where='1';
	$title='全部商品';
    $q=$_GET['q'];
	if($q!=''){
		$where.=' and title like "%'.$q.'%"';
	}
	
	if($code!=''){
		$where.=' and code="'.$code.'"';
		$title=$bankuai[$code]['title'];
	}
	if($cid>0){
		$where.=' and cid="'.$cid.'"';
		$title=$bankuai[$code]['title'];
	}

	$shuju_data=$goods_class->index_list(array('code'=>$code),$pagesize,$page,'(laiyuan_type in(1,2) or domain="jd.com") and '.$where);
	foreach($shuju_data as $k=>$row){
		if($row['id']){
			$shuju_data[$k]['url']=wap_l('goods','view',array('id'=>$row['id'],'rec'=>$dduser['id']));
		}
		else{
			$shuju_data[$k]['url']=wap_l('goods','view',array('iid'=>$row['data_id'],'rec'=>$dduser['id']));
		}
		$shuju_data[$k]['bankuai_title']=$bankuai[$row['code']]['title'];
		$shuju_data[$k]['img']=tb_img($row['img'],500);
		$shuju_data[$k]['quan_price']=$row['discount_price']-$row['price_jian'];
	}
	
	if(AJAX==1){
		echo dd_json_encode(array('s'=>1,'r'=>$shuju_data));
		dd_exit();
	}

	$parameter['shuju_data']=$shuju_data;
	$parameter['code']=$code;
	$parameter['title']=$bankuai[$code]['title'];
	$parameter['webtitle']=$title.'-首页';
	unset($duoduo);
	unset($webset);
	unset($dduser);
	unset($dd_tpl_data);
	return $parameter;
}
?>
<?php
if (!defined('INDEX')) {
	exit ('Access Denied');
}
$cid=(int)$_GET['cid'];
$parameter=act_wap_quan();
extract($parameter);
include(TPLPATH.'/inc/header_2.tpl.php');?>
<style type="text/css"> 
.lanmu{ width:100%; height:45px; font-size:14px;background:#fff;position:fixed;left:0px; top:0px;z-index:90;}
.lanmu li{ float:left;width:12.5%;text-align:center;height:45px; line-height:45px;border-bottom:1px #eee solid; }
.lanmu li a{color:#555;}
.lanmu li .jx{color:#ff3366;height:44px; border-bottom:2px #ff3366 solid; display:block}
</style>
<script>
var floorStep=2;
var ajaxTag=0;
$(function(){
	$(window).bind('scroll',function(){
		if($(window).scrollTop()+$(window).height()>=$(document).height()-400){
			if(ajaxTag==0){
				ajaxTag=1;
				jiazai(floorStep);
				floorStep++;
			}
		}
	});
	$('.shuju_load img.lazy').lazyload({
		threshold:20,
		failure_limit:50
	});
});

function index_tpl(){/*<li class="claer">   <a href="{$url}">
		            <span class="tupian"> <img data-original="{$img}" title="{$title}" class="lazy" src="<?=$dd_tpl_data['loading_img']?>" alt="{$title}" border="0"/> </span>   <?php if($row['is_new']){?><span class="xinpin"></span>  <?php }?>  </a>
					<?php if($row['price_man']>0){?>
					<a href="{$lq_url}"><div class="quan_img"><span class="num_money left">{$price_jian}</span></div></a>  <?php }?>
              <a href="{$url}"><span class="biaoti">{$title}</span></a>
                         <span class="jiage">
		                  <?php if($row['price_man']>0){?> <span class="title-tips01">券后</span><?php }?>  <span>￥</span>{$quan_price}
		                  <del>{$price}</del>
		                <span class="baoyou">{$laiyuan}</span> </span>
						  <div class="fanlibao"> 
                   <span class="fanli"> <?php if($row['fanli']>0){?> <?php if($dd_tpl_data['fl-kg']['open']==0){?> 返<span> <?=$row['fanli']?> </span><?php if($code=='jd'){?>元<?php }else{?><?=TBMONEY?>(省<span><?=$row['fanli_je']?></span>)<?php }?>  <?php }else{?><?php if($code=='jd'){?><img src="<?=TPLURL?>/inc/images/fan.png" style="vertical-align:bottom"><span> <?=$row['fanli']?> </span><?php if($code=='jd'){?><?php }else{?><?=TBMONEY?>(省<span><?=$row['fanli_je']?></span>)<?php }?><?php }else{?>热销 <span>{$sell}</span> 件<?php }?> 	<?php }?><?php }else{?>热销 <span>{$sell}</span> 件<?php }?></span></div>
                    </li>*/;}

function jiazai(floorStep){	
	$('.chakan_more').text('数据获取中……');
	var url='<?=wap_l(MOD,ACT)?>&code='+'quan'+'&q='+'<?=$_GET['q']?>'+'&cid='+'<?=$_GET['cid']?>'+'&page='+floorStep;
	$.getJSON(url,function(data){
		ajaxTag=0;
		if(data.s=='1'){
			if(data.r=='' || data.r=='null' || data.r==null){
				alert('没有了');
				ajaxTag=1;
				$('.chakan_more').hidden();
			}
			else{
				for(i in data.r){
					row=data.r[i];
					var html=getTplObj(index_tpl,row);
					$('.shuju_load').append(html);
				}
				$('.chakan_more').text('点击更多');
				$('.shuju_load img.lazy').lazyload({
					threshold:20,
					failure_limit:50
				});
			}
		}
	});
}
</script>

 <div align="center">
<div class="lanmu">
<li><a href="<?=wap_l('quan','index',array('cid'=>'10001'))?>" <?php if($cid=='10001'){?>class="jx"<?php }?>>服饰</a></li>
<li><a href="<?=wap_l('quan','index',array('cid'=>'10002'))?>" <?php if($cid=='10002'){?>class="jx"<?php }?>>鞋包</a></li>
<li><a href="<?=wap_l('quan','index',array('cid'=>'10003'))?>" <?php if($cid=='10003'){?>class="jx"<?php }?>>美妆</a></li>
<li><a href="<?=wap_l('quan','index',array('cid'=>'10004'))?>" <?php if($cid=='10004'){?>class="jx"<?php }?>>美食</a></li>
<li><a href="<?=wap_l('quan','index',array('cid'=>'10005'))?>" <?php if($cid=='10005'){?>class="jx"<?php }?>>母婴</a></li>
<li><a href="<?=wap_l('quan','index',array('cid'=>'10006'))?>" <?php if($cid=='10006'){?>class="jx"<?php }?>>居家</a></li>
<li><a href="<?=wap_l('quan','index',array('cid'=>'10007'))?>" <?php if($cid=='10007'){?>class="jx"<?php }?>>数码</a></li>
<li><a href="<?=wap_l('quan','index',array('cid'=>'10008'))?>" <?php if($cid=='10008'){?>class="jx"<?php }?>>文体</a></li>
</div>
  </div>   
		
    <div style=" margin-top:45px">
<ul class="remai2 shuju_load">
		 	  <?php foreach($shuju_data as $k=>$row){?>
		     <li class="claer">   <a href="<?=$row['url']?>">
		            <span class="tupian"> <img data-original="<?=tb_img($row['img'],800)?>" title="<?=$row['title']?>" class="lazy" src="<?=$dd_tpl_data['loading_img']?>" alt="<?=$row['title']?>" border="0"/> </span>   <?php if($row['is_new']){?><span class="xinpin"></span>  <?php }?>  </a>
					<?php if($row['price_man']>0){?>
					<a href="<?=$row['lq_url']?$row['lq_url']:'javascript:void(0)'?>"><div class="quan_img"><span class="num_money left"><?=$row['price_jian']?></span></div></a>  <?php }?>
              <a href="<?=$row['url']?>"><span class="biaoti"><?=$row['title']?></span></a>
                         <span class="jiage">
		                  <?php if($row['price_man']>0){?> <span class="title-tips01">券后</span><?php }?>  <span>￥</span><?=$row['discount_price']-$row['price_jian']?>
		                   <?php if($code=='zhidemai'){?>  <?php }else{?> <del><?=$row['price']?></del> <?php }?>
		                <span class="baoyou"><?=$row['laiyuan']?></span> </span>
						  <div class="fanlibao"> 
                   <span class="fanli"> <?php if($row['fanli']>0){?> <?php if($dd_tpl_data['fl-kg']['open']==0){?> 返<span> <?=$row['fanli']?> </span><?php if($code=='jd'){?>元<?php }else{?><?=TBMONEY?>(省<span><?=$row['fanli_je']?></span>)<?php }?>  <?php }else{?><?php if($code=='jd'){?><img src="<?=TPLURL?>/inc/images/fan.png" style="vertical-align:bottom"><span> <?=$row['fanli']?> </span><?php if($code=='jd'){?><?php }else{?><?=TBMONEY?>(省<span><?=$row['fanli_je']?></span>)<?php }?><?php }else{?>热销 <span><?=$row['sell']?></span> 件<?php }?> 	<?php }?><?php }else{?>热销 <span><?=$row['sell']?></span> 件<?php }?></span></div>
                    </li>
             <?php }?>
			 </ul>
			 
</div>
<!--<a class="chakan_more">下拉加载更多</a>-->
<div class="megas513" style="padding:10px; ">
  <?=pageft($total,$pagesize,wap_l(MOD,ACT,array('code'=>$code)),WJT)?>
</div>
 <div style="height:45px;line-height:45px; clear:both"></div>
  <a href="javascript:scroll(0,0)" hidefocus="true" title="回到顶部" id="scrollTop"></a>
<?php include(TPLPATH.'/inc/tdj.tpl.php');?>
<?php include(TPLPATH.'/inc/footer.tpl.php');?>